<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>客户端首页--用户列表</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" />
  <link rel="stylesheet" href="Styles/css/font-awesome.min.css" />

</head>

<body>
  <ul id="ulist" class="list-group">
  </ul>
  <div>
    <form id="form1">
      请选择文件:<input type="file" name="file" id="fileUpload">
      <button id="btnCheck" type="button">识别</button>
    </form>
  </div>
  <div id="result"></div>
  <script src="http://code.jquery.com/jquery-3.4.1.js" type="text/javascript"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js"></script>
  <script src="Scripts/content.min.js"></script>
  <script>
    $(function () {
      var user =JSON.parse(getStorage("user"));
      $("#result").html(user.name);
      console.log(user);
      var ulist = $("#ulist");
      $.get('http://localhost:5000/User', function (data) {
        for (var u in data) {
          ulist.append("<li class='list-group-item'><i class='fa fa-spinner fa-spin'></i><b>" + data[u].name +
            "</b>-<i>" + data[u].age + "</i></li>")
        }
      });

      $("#btnCheck").click(function () {
        var fileUrl = $("#fileUpload").prop("files");
        var fileName;        
        var reader = new FileReader();
        reader.readAsDataURL(fileUrl[0]);
        reader.onload = function (e) {
          fileName = e.target.result;
          const path=fileName.split(';')[1].split(',')[1];
          $.post("http://localhost:5000/Image",{file: path}, function (data) {
            var jsonResult = JSON.parse(data);
            //console.log(jsonResult);
            var caip = jsonResult.result[0];
            $("#result").append("识别结果:菜品:"+caip.name);
        });
        }
      });
    });
  </script>
</body>

</html>